package com.example.experiment03.Controller;

import com.example.experiment03.entity.RegionStats;
import com.example.experiment03.service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class ConfirmController {

    @Autowired
    DataService dataService;

    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String setOneModel(Model model){
        List<RegionStats> list = dataService.getList();
        model.addAttribute("allList",list);
        model.addAttribute("total", dataService.getTotalConfirmed(list));
        model.addAttribute("increased", dataService.getIncreasedConfirmed(list));
        model.addAttribute("country","全球");
        return "index";
    }

    @RequestMapping(value = "/search", method = RequestMethod.GET)
    public String setTwoModel(Model model,@RequestParam("country") String country){
        List<RegionStats> list = dataService.getDataConfirmed(country);
        model.addAttribute("allList",list);
        model.addAttribute("total", dataService.getTotalConfirmed(list));
        model.addAttribute("increased", dataService.getIncreasedConfirmed(list));
        model.addAttribute("country",country);
        return "index";
    }


}
